//
//  DoubleViewController.m
//  UIPickerViewDemo
//
//  Created by student on 16/2/23.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "DoubleViewController.h"

@interface DoubleViewController ()<UIPickerViewDataSource,UIPickerViewDelegate>

@property (nonatomic,strong) NSArray *leftList;
@property (nonatomic,strong) NSArray *rightList;

@end

@implementation DoubleViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.UIPickerView.dataSource = self;
    self.UIPickerView.delegate = self;
    self.leftList = @[@"下雨",@"下雪",@"晴天"];
    self.rightList = @[@"出去玩",@"待在家里"];
    

    
}



- (IBAction)btnPresser:(id)sender
{
    int sel1 = [self.UIPickerView selectedRowInComponent:0];
    int sel2 = [self.UIPickerView selectedRowInComponent:1];
    
    self.UILabel.text = [NSString stringWithFormat:@"因为今天%@所以%@",self.leftList[sel1],self.rightList[sel2]];
    
    
}

#pragma mark UIPickerViewDataSourceDelegate Method
//方法

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 2;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if (component == 0)
    {
        return self.leftList.count;
    }
    else
    {
        return self.rightList.count;
    }
}

- (nullable NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if (component == 0)
    {
        return self.leftList[row];
    }
    else
    {
        return self.rightList[row];
    }
}

//触发事件
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if (component == 0)
    {
        NSLog(@"当前你选择了%@",self.leftList[row]);
    }
    else
    {
        NSLog(@"当前选择了%@",self.rightList[row]);
    }
}






@end
